<form class="layui-form page-content p-4">
	{eq name="$id" value="0"}
	<h3 class="h3-title">新增公告</h3>
	{else/}
	<h3 class="h3-title">编辑公告</h3>
	{/eq}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray">公告标题<font>*</font></td>
			<td>
				<input type="text" name="title" lay-verify="required" lay-reqText="请输入公告标题" placeholder="请输入公告标题" class="layui-input"
			  {notempty name="$note.title" }value="{$note.title}" {/notempty}>
			</td>
			<td class="layui-td-gray">公告分类<span style="color: red">*</span></td>
			<td>
				<select name="cate_id" lay-verify="required" lay-reqText="请选择分类">
					<option value="">请选择分类</option>
					{notempty name="$note.cate_id"}
						{volist name=":set_recursion(admin_note_cate())" id="v"}
						<option value="{$v.id}" {eq name="$note.cate_id" value="$v.id" }selected{/eq}>{$v.title}</option>
						{/volist}
					{else/}
						{volist name=":set_recursion(admin_note_cate())" id="v"}
						<option value="{$v.id}">{$v.title}</option>
						{/volist}
					{/notempty}
				</select>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">展示期间<span style="color: red">*</span></td>
			<td id="date">
				<div class="layui-input-inline">
					<input type="text" id="start_time" name="start_time" readonly lay-verify="required" lay-reqText="请选择公告展示开始时间" placeholder="请选择时间" class="layui-input" {notempty name="$note.start_time" }value="{$note.start_time | date='Y-m-d'}" {/notempty}>
				</div>
				-
				<div class="layui-input-inline">
					<input type="text" id="end_time" name="end_time" readonly lay-verify="required" lay-reqText="请选择公告展示结束时间" placeholder="请选择时间" class="layui-input" {notempty name="$note.end_time" }value="{$note.end_time | date='Y-m-d'}" {/notempty}>
				</div>
			</td>
			<td class="layui-td-gray">排序</td>
			<td>
				<input type="text" name="sort" placeholder="请输入排序，数字" class="layui-input" {notempty
			  name="$note.sort" }value="{$note.sort}" {/notempty}>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray" style="vertical-align:top; text-align:left;" colspan="4">公告内容<span style="color: red">*</span></td>
		</tr>
		<tr>
			<td colspan="4">
			<div style="margin-top:-2px; margin-right:2px">
				<textarea id="mdContent" style="display:none;">{notempty name="$note.md_content" }{$note.md_content|raw}{/notempty}</textarea>
				<div id="docContent"></div>
			</div>
			</td>
		
		<tr>
			<td class="layui-td-gray">关联链接</td>
			<td colspan="3">
				<input type="text" name="src" placeholder="请输入链接" class="layui-input" {notempty
			  name="$note.src" }value="{$note.src}" {/notempty}>
			</td>
		</tr>
	</table>

	<div class="pt-3">
		<input type="hidden" name="id" value="{$id}" />
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>

<script>
	function openInit() {
		var form = layui.form,
			layer = layui.layer,
			tool = layui.tool,
			editor = layui.editormd,
			laydate = layui.laydate;
			
	form.render();
	var edit = editor.render('docContent', {
		markdown: $('#mdContent').val(),
		imageUploadURL: "/api/index/md_upload",
		lineNumbers: false,
		toolbarIcons: function () {
			return [
				"undo", "redo","bold", "del", "italic", "quote","h1", "h2", "h3", "h4", "h5",
				"list-ul", "list-ol", "hr","link", "reference-link", "image", "code", "code-block", "table","watch", "fullscreen"
			];
		},
		height:window.innerHeight - 350
	});
	//日期范围
	laydate.render({
		elem: '#date',
		range: ['#start_time', '#end_time']
	});
    //监听提交
    form.on('submit(webform)', function (data) {
		let callback = function (e) {
			layer.msg(e.msg);
			if (e.code == 0) {
				tool.close(1000);
			}
		}
		tool.post("/admin/note/add",data.field,callback);
		return false;
    });
}

</script>